package com.douqu.game.activity.server;

import com.douqu.game.activity.GameServer;
import com.douqu.game.activity.entity.MainServerInfo;
import com.douqu.game.activity.manager.ActivityCampManager;
import com.douqu.game.core.factory.DataFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ScheduledTask {


    private int updateCount;

    ActivityCampManager activityCampManager = GameServer.getInstance().getActivityCampManager();

    /**
     * PING
     * @throws InterruptedException
     */
    @Scheduled(fixedRate = 500000)
    public void pingMainServer() throws Exception
    {
        for(MainServerInfo mainServerInfo : GameServer.getInstance().getMainServerList())
        {
            mainServerInfo.sendPing();
        }
    }

    /**
     * 更新
     * @throws InterruptedException
     */
    @Scheduled(fixedRate = 500)
    public void updateTime() throws Exception
    {
        DataFactory.currentTime = System.currentTimeMillis();

        if(++updateCount == 2)
        {
            updateCount = 0;
            activityCampManager.update(1000);
        }
    }


//    /**
//     * 阵营活动时间
//     */
//    @Scheduled(cron = CampActivityFactory.CRON_TIME)
//    public void campActivityMatch() throws Exception
//    {
//        GameServer.getInstance().getActivityCampManager().match();
//
//        GameServer.getInstance().getActivityCampManager().save();
//    }
}